"""
@File    :   custom_async_validator.py
@Time    :   2024/03/24 23:12:52
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   自定义pydantic异步验证失败异常
"""

from fastapi.exceptions import RequestValidationError


def generate_async_validator_exception(
    column_name: str, err_msg: str
) -> RequestValidationError:
    """生成异步验证异常

    Args:
        column_name (str): 字段名
        err_msg (str): 错误信息

    Returns:
        RequestValidationError: fastapi的验证异常类
    """
    return RequestValidationError(
        [
            {
                "type": "custom_async_validator",
                "loc": ("async_validator", column_name),
                "msg": err_msg,
            }
        ]
    )
